using System;
using System.Runtime.InteropServices;

namespace NovaCore.Interop {
	[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
	public struct DeviceDetail {
		public DeviceTechType eTechnology;
		public DeviceFormFactorType eFormFactor;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NvtlConstants.NW_MAX_PATH)]
		public string szDescription;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NvtlConstants.NW_MAX_PATH)]
		public string szPort;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NvtlConstants.NW_MAX_PATH)]
		public string szFriendlyName;
	}

	[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
	public struct DeviceInfoStruct {
		public int dwSize;
		public int dwCurFWVersion;
		public SourceBuildBaseType eBuildBase;
		public ServiceProviderType eSrvProvider;
		public DeviceTechType eTech;
		public DeviceFormFactorType eFormFactor;
		public DeviceStateType eState;

		public DeviceModeType modeDevice;
		public CallStatusType connStatus;

		public byte bDeviceLocked;
		public byte maskWDisable;
		public byte subsysID;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NvtlConstants.NW_SIZE_NAME * 2)]
		public string szSoftwareVersion;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NvtlConstants.NW_SIZE_NAME)]
		public string szDeviceModel;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NvtlConstants.NW_SIZE_NAME)]
		public string szHardwareVersion;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NvtlConstants.NW_SIZE_NAME)]
		public string szDriverVersion;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NvtlConstants.NW_SIZE_NUMBER)]
		public string szMDN;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NvtlConstants.NW_SIZE_NAME)]
		public string szFID;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NvtlConstants.NW_SIZE_NUMBER)]
		public string szIMEI;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NvtlConstants.NW_SIZE_NAME)]
		public string szSMSC;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NvtlConstants.NW_SIZE_NUMBER)]
		public string szIMSI;
		
		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NvtlConstants.NW_SIZE_NUMBER)]
		public string szICCID;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NvtlConstants.NW_SIZE_NUMBER)]
		public string szMIN;

		public int dwESN;
		public int dwPRLVersion;
		public int dwERIVersion;
		public int dwHomeSID;
	}

	public struct SmsMessageStruct {
		public int eSMSType;
		public int eState;
		public int index;
		public int data_len;
		public byte[] data;
	}

	public struct NvtlEventCallback {
		public IntPtr user_data;
		public NvtlSdkEventFunc event_func;
	}

	public struct tm {
		public int tm_sec;
		public int tm_min;
		public int tm_hour;
		public int tm_mday;
		public int tm_mon;
		public int tm_year;
		public int tm_wday;
		public int tm_yday;
		public int tm_isdst;

		public DateTime ToDateTime() {
			return new DateTime(tm_year, tm_mon + 1, tm_mday, tm_hour, tm_min, tm_sec);
		}

		public static tm FromDateTime(DateTime dt) {
			return new tm {
				tm_year = dt.Year,
				tm_mon = dt.Month - 1,
				tm_mday = dt.Day,
				tm_hour = dt.Hour,
				tm_min = dt.Minute,
				tm_sec = dt.Second,
				tm_wday = (int)dt.DayOfWeek,
				tm_yday = dt.DayOfYear,
				tm_isdst = -1 // not available
			};
		}
	}
}